<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/6/26
 * Time: 10:44
 */
namespace Admin\Model;
use Base\Model\BaseModel;
class DoctorInfoModel extends BaseModel {
    protected $dbName = 'transplant_userinformation';
    protected $_validate = array(
        array('realname', 'require', '真实姓名必须填写'),
        array('phone', '', '手机号已存在', 0, 'unique', 2),
//        array('email', '', '邮箱格式不正确', 0, 'unique', 3),
        array('email', 'email', '邮箱格式不正确！', 2),
        array('idcard','checkIdCard', '身份证位数不正确',2),
        array('idcard', '', '亲，每一个人的身份证是独一无二滴！',2),
    );
    protected $_auto = array(
        array('passwd','',2,'ignore'),//表示passwd字段编辑的时候留空则忽略。
        array('certCover','',2,'ignore'),//表示certCover字段编辑的时候留空则忽略。
        array('status', '3'),
        array('createTime','mydate','1','callback'),
        array('lastEditTime','mydate','3','callback'),
    );
    protected function mydate(){
        return date("Y-m-d H:i:s");
    }
    /**
    *简单的验证身份证
    */
   protected function checkIdCard($idcard){  
        if(empty($idcard)){  
            return false;  
        }  
            if(!preg_match('/^\d{17}(\d|x)$/i',$idcard) and!preg_match('/^\d{15}$/i',$idcard))
        {  
            return false;  
        }  
    }
    protected $_link=array(
        //省市
        'province' => array(
            'mapping_type' => self::BELONGS_TO,
            'class_name'    => 'aerainfo',
            'foreign_key' => 'provenceid',
            'parent_key' => 'id',
            'mapping_fields' => 'aerainfo_id,aerainfo_name'
        ),
        //市县
        'city' => array(
            'mapping_type' => self::BELONGS_TO,
            'class_name'    => 'aerainfo',
            'foreign_key' => 'cityid',
            'parent_key' => 'id',
            'mapping_fields' => 'aerainfo_id,aerainfo_name'
        ),
        //县区
        'region' => array(
            'mapping_type' => self::BELONGS_TO,
            'class_name'    => 'aerainfo',
            'foreign_key' => 'regionid',
            'parent_key' => 'id',
            'mapping_fields' => 'aerainfo_id,aerainfo_name'
        ),
          //血型
          'blood' => array(
            'mapping_type' => self::BELONGS_TO,
            'class_name'    => 'bloodtypeinfo',
            'foreign_key' => 'bloodid',
            'parent_key' => 'id',
            'mapping_fields' => 'id,name'
        ),
        //科室
        'department' => array(
            'mapping_type' => self::BELONGS_TO,
            'class_name'    => 'departmentinfo',
            'foreign_key' => 'officeid',
            'parent_key' => 'id',
            'mapping_fields' => 'id,name'
        ),
        //医院
        'hospital' => array(
            'mapping_type' => self::BELONGS_TO,
            'class_name'    => 'hospitalinfo',
            'foreign_key' => 'hospitalid',
            'parent_key' => 'id',
            'mapping_fields' => 'id,name'
        ),
        //职称
        'position' => array(
            'mapping_type' => self::BELONGS_TO,
            'class_name'    => 'positioninfo',
            'foreign_key' => 'titleid',
            'parent_key' => 'id',
            'mapping_fields' => 'id,name'
        ),
    );
}